package com.yunqiao.admin.modules.api.controller;

import com.yunqiao.common.utils.PageUtils;
import com.yunqiao.common.utils.R;
import com.yunqiao.service.api.CarTypeService;
import com.yunqiao.service.api.entity.CarTypeEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 车辆类型表
 *
 * @author Crocutax
 * @email wangxw725@163.com
 * @date 2019-03-02 15:04:03
 */
@RestController
@RequestMapping("api/cartype")
public class CarTypeController {

    @Autowired
    private CarTypeService carTypeService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("api:cartype:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = carTypeService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 获取所有列表
     */
    @RequestMapping("/getCarType")
    public R getCarType(){
        List<Object> list = carTypeService.getCarType();
        return R.objectOk(list);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("api:cartype:info")
    public R info(@PathVariable("id") Integer id){
        CarTypeEntity carType = carTypeService.getById(id);
        return R.ok().put("carType", carType);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("api:cartype:save")
    public R save(@RequestBody CarTypeEntity carType){
        carTypeService.save(carType);
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("api:cartype:update")
    public R update(@RequestBody CarTypeEntity carType){
        carTypeService.updateById(carType);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("api:cartype:delete")
    public R delete(@RequestBody Integer[] ids){
        carTypeService.removeByIds(Arrays.asList(ids));
        return R.ok();
    }

}
